package main

import (
	"fmt"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
)

type AlertRule struct {
	Groups []Group `yaml:"groups"`
}

type Group struct {
	Name  string `yaml:"name"`
	Rules []Rule `yaml:"rules"`
}

type Rule struct {
	Alert       string            `yaml:"alert"`
	For         string            `yaml:"for"`
	Annotations map[string]string `yaml:"annotations"`
	Expr        string            `yaml:"expr"`
	Labels      map[string]string `yaml:"labels"`
}

func main3() {
	/// Open the YAML file
	file, err := ioutil.ReadFile("E:\\application\\开发环境归档\\omc-prometheus-alert\\overlays\\tempnode\\tempregion\\omc-prometheus-alert-0-rule.yaml")
	if err != nil {
		log.Fatalf("Failed to read file: %v", err)
	}

	// Parse the YAML file into the Config struct
	var alertRule AlertRule
	err = yaml.Unmarshal(file, &alertRule)
	if err != nil {
		log.Fatalf("Failed to parse YAML: %v", err)
	}

	// Access the data from the Config struct
	fmt.Println(alertRule.Groups[0].Name)
	fmt.Println(alertRule.Groups[0].Rules[0].Alert)
	fmt.Println(alertRule.Groups[0].Rules[0].Annotations["value"])
	fmt.Println(alertRule.Groups[0].Rules[0].Labels["rule_id"])
	fmt.Println(alertRule.Groups[0].Rules[0].Labels["__replica__"])
}
